﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class SubmitFeedback : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            SubmitFeedbackOutParam result = new SubmitFeedbackOutParam();
            SubmitFeedbackInParam param = new SubmitFeedbackInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as SubmitFeedbackInParam;

                if (string.IsNullOrEmpty(param.Sign_mode) || (param.Sign_mode != "0" && param.Sign_mode != "1"))
                {
                    result.code = "0";
                    result.desc = "署名方式不正确";

                    isFlag = false;
                }

                if(string.IsNullOrEmpty(param.Message_Content) || string.IsNullOrEmpty(param.User_ID))
                {
                    result.code = "0";
                    result.desc = "意见详情，用户ID不能为空";

                    isFlag = false;
                }

                if (isFlag)
                {
                    if (CommonUtils.IsDisableUsers(param.User_ID))
                    {
                        result.code = "0";
                        result.desc = "用户状态有问题，请联系管理员";

                        isFlag = false;
                    }
                }

                if (isFlag && param.Sign_mode == "1")
                {
                    if (string.IsNullOrEmpty(param.Name) || string.IsNullOrEmpty(param.Mobile))
                    {
                        result.code = "0";
                        result.desc = "实名情况下，姓名、联系电话不能为空";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    param.Sort_1Desc = Sort1Parse(param.Sort_1);
                    if (string.IsNullOrEmpty(param.Sort_1Desc))
                    {
                        result.code = "0";
                        result.desc = "类别1不正确";

                        isFlag = false;
                    }
                }

                if (isFlag && param.Sort_1 == "0")
                {
                    param.Sort_2Desc = Sort2Parse(param.Sort_2);
                    if (string.IsNullOrEmpty(param.Sort_2Desc))
                    {
                        result.code = "0";
                        result.desc = "类别2不正确";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    param.DepartmentID = InterfaceHelper.GetToDepartmentID(param.Department);
                    if (string.IsNullOrEmpty(param.DepartmentID))
                    {
                        result.code = "0";
                        result.desc = "意见归属部门不正确";

                        isFlag = false;
                    }
                }
                 
                if(isFlag)
                {
                    if(!InterfaceHelper.InsertPartyFeedback(param))
                    {
                        result.code = "0";
                        result.desc = "提交失败，请重试";

                        isFlag = false;
                    }
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }
    
            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-SubmitFeedback", SerializeHelper.JsonSerializer<SubmitFeedbackInParam>(param), logMsg); 
            return result as OutParam;
        }

        private string Sort1Parse(string sort1)
        {
            switch (sort1)
            {
                case "0":
                    return "作风方面";
                case "1":
                    return "宗旨意识";
                case "2":
                    return "廉洁自律";
                case "3":
                    return "其他"; 
                default:
                    return "";
            }
        }

        private string Sort2Parse(string sort2)
        {
            switch (sort2)
            {
                case "0":
                    return "形式主义";
                case "1":
                    return "官僚主义";
                case "2":
                    return "享乐主义";
                case "3":
                    return "奢靡之风";
                case "4":
                    return "其他";
                default:
                    return "";
            }
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<SubmitFeedbackInParam, SubmitFeedbackOutParam>();
            else
                SafeProcessRequest<SubmitFeedbackInParam, SubmitFeedbackOutParam>();
        }
    }

    #region 请求参数
    public class SubmitFeedbackInParam
    {
        /// <summary>
        /// 用户ID
        /// </summary>
        public string User_ID
        { get; set; }

        /// <summary>
        ///	署名方式	0.匿名；1.实名
        /// </summary>
        public string Sign_mode
        { get; set; }  

        /// <summary>
        /// 姓名
        /// </summary>
        public string Name
        { get; set; }

        /// <summary>
        /// 联系电话
        /// </summary>
        public string Mobile
        { get; set; }

        /// <summary>
        /// 类别1		0.作风方面；1.宗旨意识；2.廉洁自律；3.其他
        /// </summary>
        public string Sort_1
        { get; set; }

        public string Sort_1Desc
        { get; set; }

        /// <summary>
        /// 类别2		0.形式主义；1.官僚主义；2.享乐主义；3.奢靡之风；4。其他
        /// </summary>
        public string Sort_2
        { get; set; }

        public string Sort_2Desc
        { get; set; }

        /// <summary>
        /// 意见归属部门		部门名称
        /// </summary>
        public string Department
        { get; set; }

        public string DepartmentID
        { get; set; }

        /// <summary>
        /// 意见详情
        /// </summary>
        public string Message_Content
        { get; set; }    
    }
    #endregion

    #region 结果参数
    public class SubmitFeedbackOutParam
    {
        public SubmitFeedbackOutParam()
        {
            code = "1";
            desc = "操作成功"; 
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; } 
    } 
    #endregion 
}